import json

from api.base_service import BaseService


class MemberService(BaseService):
    def find_by_telephone(self, tel: str):
        resp = self.dubbo_client.invoke("MemberService", "findByTelephone", tel)
        if resp == "null":
            return None
        return json.loads(resp)

    def add(self, member):
        member["class"] = "com.itheima.pojo.Member"
        resp = self.dubbo_client.invoke("MemberService", "add", member)
        if resp == "null":
            return True
        return False

    def find_member_count_by_month(self, months: list):
        resp = self.dubbo_client.invoke("MemberService", "findMemberCountByMonth", months)
        if resp == "Failed":
            return None
        return json.loads(resp)

if __name__ == '__main__':
    # print("resp = ",MemberService().find_by_telephone("18512345678"))
    print(MemberService().add({"name": "a", "phoneNumber":"18512345678"}))
    # res = MemberService().find_member_count_by_month(["1999.4"])
    # print("res =", res, type(res))

